home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / smail-3.1.28 / pd / sdbm / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-12  |  994 b   |  68 lines

  1. /* @(#)pd/sdbm/util.c    1.1 5/12/92 11:03:56 */
  2. #include "defs.h"
  3. #ifdef SDBM
  4. #include "sdbm.h"
  5. #else
  6. #include <ndbm.h>
  7. #endif
  8. #include <stdio.h>
  9.  
  10. #ifdef ANSI_C
  11. #include <string.h>
  12. #include <errno.h>
  13. #else
  14. extern int errno, sys_nerr;
  15. extern char *sys_errlist[];
  16. #endif
  17.  
  18. extern char *progname;
  19.  
  20. void
  21. oops(s1, s2)
  22. register char *s1;
  23. register char *s2;
  24. {
  25.     int e = errno;
  26.     char *emsg = NULL;
  27.  
  28.     if (progname)
  29.         fprintf(stderr, "%s: ", progname);
  30.     fprintf(stderr, s1, s2);
  31. #ifdef ANSI_C
  32.     emsg = strerror(e);
  33. #else
  34.     if (e > 0 && e < sys_nerr)
  35.         emsg = sys_errlist[e];
  36. #endif
  37.     if (emsg)
  38.         fprintf(stderr, " (%s)", emsg);
  39.     fprintf(stderr, "\n");
  40.     exit(1);
  41. }
  42.  
  43. int
  44. okpage(pag)
  45. char *pag;
  46. {
  47.     register unsigned n;
  48.     register off;
  49.     register short *ino = (short *) pag;
  50.  
  51.     if ((n = ino[0]) > PBLKSIZ / sizeof(short))
  52.         return 0;
  53.  
  54.     if (!n)
  55.         return 1;
  56.  
  57.     off = PBLKSIZ;
  58.     for (ino++; n; ino += 2) {
  59.         if (ino[0] > off || ino[1] > off ||
  60.             ino[1] > ino[0])
  61.             return 0;
  62.         off = ino[1];
  63.         n -= 2;
  64.     }
  65.  
  66.     return 1;
  67. }
  68.